#pragma once
// Networking libraries
#include<iostream>
#include <winsock2.h>
#include <Windows.h>
#include <ws2tcpip.h>
#include <stdio.h> 
using namespace std;

#define MAX_PACKET_SIZE 1000

// size of our buffer
#define DEFAULT_BUFLEN 512
// port to connect sockets through 
#define DEFAULT_PORT "6881"
// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")

class ClientNetwork
{
	int portNumber;
	char *Server_Address;

public:

    // for error checking function calls in Winsock library
    unsigned long iResult;

    // socket for client to connect to server

	struct addrinfo *result ,
                    *ptr ,
                    hints;
    char *sendbuf;
    char recvbuf[1024];
    unsigned long no;

	WSADATA wsaData;

    SOCKET ConnectSocket;

	class ConexiuneEronata
	{
		string mes;
		int cod;
	public:
		ConexiuneEronata(char *m,int c):mes(m)
		{
			cod=c;
		}

		void printEroare()const
		{
			cout<<mes.c_str();
		}

		int daCod()const
		{
			return cod;
		}
	};

    // ctor/dtor
    ClientNetwork(void);

	ClientNetwork(char *ServerAdd,int );

    ~ClientNetwork(void);

	int MyClientConnection(char* , int port);

	int sendPackets(char *);

	int sendPackets(char *,int size);

	int receivePackets(char* );

	int CloseMyConnection();
};